<template>
  <el-dialog title="客户充值" width="40%" :before-close="dialogClose" :visible.sync="show">
      <el-form ref="form" label-width="100px">
          <el-form-item label="充值金额" style="margin-top:20px;">
              <el-input type="number" placeholder="充值金额" @input="give" v-model="form.pay_money"></el-input>
          </el-form-item>
          <el-form-item label="赠送代金券" style="margin-top:20px;">
              <el-input type="number" placeholder="赠送代金券" @input="give" v-model="form.give_money"></el-input>
          </el-form-item>
          <el-form-item label="应收金额" style="margin-top:20px;">
              <el-input type="number" placeholder="应收金额" v-model="money"></el-input>
          </el-form-item>
          <el-form-item label="实收金额" style="margin-top:20px;">
              <el-input type="number" placeholder="实收金额" v-model="form.pay_money"></el-input>
          </el-form-item>
          <div align="center" style="margin-top:20px;">
            <el-button type="primary" @click="rechargeSubmit">确 定</el-button>
            <el-button @click="dialogClose">取 消</el-button>
          </div>
      </el-form>
  </el-dialog>
</template>
 
<script>
export default {
  name: 'addRecharge',
  props:['show','id'],
  data() {
    return {
        form:{},
        money:0
    }
  },
  created: function(){
    
  },
  methods: {
    dialogClose:function(){
      this.$emit("func",{'key':'addRecharge'})
    },
    give:function(){
			if(this.form.pay_money){
				var pay = this.form.pay_money
			}else{
				var pay = 0
			}
			if(this.form.give_money){
				var give = this.form.give_money
			}else{
				var give = 0
			}
			this.money = parseFloat(pay) + parseFloat(give)
		},
    rechargeSubmit:function(){
      if(!this.form.pay_money){
        this.$message.error('充值金额不能为空!');
        return;
			}
      this.form.member_id = this.id
      this.form.oa_id = localStorage.getItem('oa_id')
      var that = this
      this.$post('manage/recharge/add',this.form).then((res) => {
          if(res.code == 1){
            that.$message.success('充值成功!!')
            that.$emit("func",{'key':'addRecharge','update':1})
          }else{
            that.$message.error(res.msg);
          }
      })
    }
  }
}
</script>
<style>
.skinList_checkbox{
    display: flex;
    flex-direction:row;
    justify-content:flex-start;
    flex-wrap:wrap;
}
.skinList_checkbox label{
  margin-top:20px;
}
.el-checkbox.is-bordered:first-child{
  margin-left:10px;
}
</style>